﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FirstFloor.ModernUI.Windows;
using FirstFloor.ModernUI.Windows.Controls;
using Lephone.Data;

namespace SimlvClient.Pages
{
    /// <summary>
    /// Interaction logic for UserList.xaml
    /// </summary>
    public partial class UserList : UserControl
    {
        public UserList()
        {
            InitializeComponent();
            GetGridData();
        }

        public void GetGridData()
        {
            try
            {
                var NewsList = DbEntry.From<SimlvClient.Model.User>().Where(Lephone.Data.Condition.Empty).OrderByDescending(o => o.Id).Select().ToList();
                gridNews.ItemsSource = NewsList;
            }
            catch (Exception ex)
            {
            }
        }

        #region command
       
        #region button click
        private void AddCommand(object sender, RoutedEventArgs e)
        {

            UserDetail NewPage = new UserDetail(null);
            NewPage.Height = 600;
            NewPage.Width = 800;
            if (NewPage.ShowDialog().Value)
            {
                GetGridData();
            }
            else
            {
               GetGridData();
            }
        }

        private void EditCommand(object sender, RoutedEventArgs e)
        {
            var SelectModel = gridNews.SelectedItem as Model.User;
            if (SelectModel != null)
            {
                UserDetail NewPage = new UserDetail(SelectModel);
                NewPage.Height = 600;
                NewPage.Width = 800;
                if (NewPage.ShowDialog().Value)
                {
                    GetGridData();
                }
                else
                {
                    GetGridData();
                }
            }


        }
        private void DeleteCommand(object sender, RoutedEventArgs e)
        {

            if (gridNews.SelectedItem != null)
            {
                var SelectModel = gridNews.SelectedItem as Model.User;
                if (SelectModel != null)
                {
                    SelectModel.Delete();
                    GetGridData();
                    ModernDialog.ShowMessageText("删除成功！");
                }
            }
        }
        #endregion
        #endregion
    }
}
